<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/iCheck/custom.css}" rel="stylesheet"/>

<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <!-- 生产部主管审批页面 -->
    <!-- 我的待审-审批 -->
    <form class="form-horizontal m" id="formId" name="formId" th:object="${Form}" enctype="multipart/form-data">
        <input id="id" name="id" class="form-control" th:value="*{id}" type="hidden">
        <input  class="form-control" th:value="*{procInstanId}" type="hidden">
        <input id="id" name="taskId" class="form-control" type="hidden" th:value="${taskId}">
        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">标题(Title)：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<input readonly="readonly" name="title" th:value="*{title}" class="form-control" value="test" type="text">-->
            <!--</div>-->
        <!--</div>-->

        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">类型：</label>-->
            <!--<div class="col-sm-8 form-control-static" th:text="*{leaveType}">-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">申请人(Requestor)：</label>
            <div class="col-sm-8">
                <input readonly="readonly" id="proposer_Id" name="proposer_Id" class="form-control" type="text" th:field="*{proposer_Id}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">客户(Customer)：</label>
            <div class="col-sm-8">
                <input readonly="readonly" id="customer" name="customer" class="form-control" type="text" th:field="*{customer}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">支持项目(Project)：</label>
            <div class="col-sm-8">
                <input readonly="readonly" id="supportingProject" name="supportingProject" class="form-control" type="text" th:field="*{supportingProject}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">普工(Normal)：</label>
            <div class="col-sm-3">
                <input readonly="readonly" id="requestedOne" name="requestedOne" class="form-control" type="text" th:field="*{requestedOne}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">缝工(Sewing)：</label>
            <div class="col-sm-3">
                <input readonly="readonly" id="requestedTwo" name="requestedTwo" class="form-control" type="text" th:field="*{requestedTwo}">
            </div>
        </div>

        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">需求开始时间：</label>-->
            <!--<div class="col-sm-8 form-control-static" th:text="*{#dates.format(leaveTime,'yyyy-MM-dd HH:mm:ss')}">-->
            <!--</div>-->
        <!--</div>-->

        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">需求结束时间：</label>-->
            <!--<div class="col-sm-8 form-control-static" th:text="*{#dates.format(expireTime,'yyyy-MM-dd HH:mm:ss')}">-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">开始时间(Start Time)：</label>
            <div class="col-sm-8">
                <input readonly="readonly" th:value="*{#dates.format(leaveTime,'yyyy-MM-dd HH:mm')}"  id="leaveTime" class="form-control" type="text" placeholder="yyyy-MM-dd HH:mm">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">结束时间(End Time)：</label>
            <div class="col-sm-8">
                <input readonly="readonly" th:value="*{#dates.format(expireTime,'yyyy-MM-dd HH:mm')}" id="expireTime" class="form-control" type="text" placeholder="yyyy-MM-dd HH:mm">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">时间合计(Total Time)：</label>
            <div class="col-sm-8">
                <input readonly="readonly" th:value="*{totalTime}" id="totalTime" class="form-control" type="text" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注(Remark)：</label>
            <div class="col-sm-8">
                <textarea readonly="readonly" name="leaveContent" type="text" th:text="*{leaveContent}"
                          class="form-control"></textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上级审批状态:</br>(Status)</label>
            <div class="col-sm-8">
                <label class="checkbox-inline i-checks">
                    <span th:if="*{status} eq '1'" class="btn btn-warning btn-xs ">待审批</span>
                    <span th:if="*{status} eq '2'" class="btn btn-success btn-xs ">同意</span>
                    <span th:if="*{status} eq '3'" class="btn btn-danger btn-xs ">拒绝</span>
                </label>
            </div>
        </div>
        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">下一个审批人:</br>(next approver)</label>-->
            <!--<div class="col-sm-8">-->
                <!--&lt;!&ndash;<input name="roomName" type="text" th:value="${roomName}"  class="form-control"/>&ndash;&gt;-->
                <!--<select name="agent_Id" class="form-control">-->
                    <!--&lt;!&ndash;<option value="">&#45;&#45;</option>&ndash;&gt;-->
                    <!--&lt;!&ndash;<option th:each="user:${users}" th:value="${user.uid}" th:text="${user.name}"></option>&ndash;&gt;-->
                    <!--<option th:each="approver:${approver}" th:value="${approver.uid}" th:text="${approver.name}"></option>-->
                <!--</select>-->
                <!--&lt;!&ndash; 正式上线切换开始 &ndash;&gt;-->
                <!--&lt;!&ndash;<input readonly="readonly" id="name" name="agent_Id" th:value="${approver.uid}" th:field="${approver.name}" class="form-control"  type="text">&ndash;&gt;-->
                <!--&lt;!&ndash; 正式上线切换结束 &ndash;&gt;-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">部门经理审批意见：</br>(Department manager approves opinions)</label>
            <div class="col-sm-8">
                <textarea readonly="readonly" name="leaveContent" type="text" th:text="*{reply}"
                          class="form-control"></textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">您的审批意见:</br>(Your approval opinion)</label>
            <div class="col-sm-8">
                <textarea  type="text" name="replyTwo"
                          class="form-control"></textarea>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label" >状态(Status)：</label>
            <div class="col-sm-8">
                <label class="checkbox-inline i-checks">
                    <input id="fileStatus" type="radio" name="status" value="5" checked/>
                    同意
                </label>
                <label class="checkbox-inline i-checks">
                    <input type="radio" name="status" value="6"/>
                    拒绝
                </label>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">文件(File)：</label>
            <div class="col-sm-8">
                <input name="file" onchange="change()" id="file" class="form-control" type="file">
            </div>
        </div>
        <!--<div class="form-group" id="size" style="display: none">-->
            <!--<label class="col-sm-3 control-label" for="FileSize">大小：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<input class="form-control" id="FileSize" type="text">-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group" shiro:hasPermission="task:update2" >
            <div class="form-control-static col-sm-offset-9">
                <button type="submit" class="btn btn-primary" >审批</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script type="text/javascript">

    var prefix = "/task";
    var prefix2 = "/file";
    var filemaxsize = 10485760;//10485760=50Mb
    $("#formId").validate({
        rules:{
            agent_Id:{
                required:true,
            }
            ,
            replyTwo:{
                required:true,
            }

        },
        submitHandler: function(form) {
            $.operate.save(prefix + "/LeaveApproval", $('#formId').serialize());

            //文件上传新增开始
            var fileSize = document.getElementById("file").files[0].size;
            var fileStatus = document.getElementById("fileStatus");
            var file = document.getElementById("file");

            if (fileSize > filemaxsize) {
                $.modal.alertError('附件大小不能大于' + filemaxsize / 1024 + 'M！\r\n');
                return false;
            }

//            if (fileStatus == 5 && file == null){
//                $.modal.alertError("请上传文件!");
//                return false;
//            }


//            var key = layer.msg('正在上传...', {
//                icon: 16
//                , shade: 0.1
//                , time: 60000
//            });


            var formData = new FormData(document.getElementById("formId"));//表单id
            $.ajax({
                url: prefix2 + '/addSave',
                type: 'POST',
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    $.operate.saveSuccess(result);
                },
                error: function () {
                    $.modal.alertError("系统错误");
                }
            });//文件上传新增结束
        }
    });

    //*********************** 文件上传JS 开始***********************************
    function change() {
        $("#size").show();
        var fileSize = document.getElementById("file").files[0].size;
        var size = (fileSize / 1024 / 1024).toFixed(2) + "MB";
        if (fileSize > filemaxsize) {
            $("#FileSize").val(size).css("border-color", "red");
        } else {
            $("#FileSize").val(size);
        }
    }

    //*********************** 文件上传JS 结束***********************************

</script>
</body>
</html>
